package io.zhengsh.vvip.jvm.proxy;

import net.sf.cglib.proxy.Enhancer;
import net.sf.cglib.proxy.MethodInterceptor;

public class OrderServiceImpl implements OrderService {
    @Override
    public OrderDto createOrder(OrderDto orderDto) {
        System.out.println("OrderServiceImpl#createOrder !!!");
        return null;
    }

    public static void main(String[] args) {
        OrderServiceImpl orderService = new OrderServiceImpl();
        Enhancer enhancer = new Enhancer();
        enhancer.setSuperclass(orderService.getClass());
        enhancer.setCallback((MethodInterceptor)(obj, method, args1, proxy) -> {
            System.out.println("before !!!!");
            Object o = proxy.invokeSuper(obj, args1);
            System.out.println("after  !!!!");
            return o;
        });
        OrderServiceImpl orderServiceProxy = (OrderServiceImpl)enhancer.create();
        orderServiceProxy.createOrder(new OrderDto());
    }
}
